package com.easemob.chat;

import com.easemob.util.EMLog;
import org.jivesoftware.smack.packet.Message;
import org.jivesoftware.smack.packet.Message.Type;
import org.jivesoftware.smack.util.StringUtils;

class GroupChatListener extends ChatListener
{
  private static final String TAG = "groupchatlistener";

  public GroupChatListener(EMChatManager paramEMChatManager)
  {
    super(paramEMChatManager);
  }

  protected boolean processMessage(Message paramMessage)
  {
    ackMessage(paramMessage);
    String str1 = paramMessage.getFrom();
    String str2 = str1.substring(str1.lastIndexOf("/") + 1);
    if (EMChatManager.getInstance().getCurrentUser().equals(str2))
      return true;
    if ((paramMessage.getBody() == null) || (paramMessage.getBody().equals("")))
      return true;
    if (isDuplicateMsg(paramMessage))
    {
      EMLog.d("groupchatlistener", "ignore duplicate msg");
      return true;
    }
    String str3 = StringUtils.parseBareAddress(paramMessage.getFrom());
    EMLog.d("groupchatlistener", "groupchat listener receive msg from:" + str3 + " body:" + paramMessage.getBody());
    if (paramMessage.getType() != Message.Type.groupchat)
      return false;
    EMMessage localEMMessage = MessageEncoder.parseXmppMsg(paramMessage);
    if (localEMMessage == null)
      return false;
    if (localEMMessage.getFrom().equals(EMChatManager.getInstance().getCurrentUser()))
    {
      EMLog.d("groupchatlistener", "igore group msg sent from myself:" + localEMMessage.toString());
      return false;
    }
    processGroupMessage(paramMessage, localEMMessage);
    if (paramMessage.getExtension("encrypt", "jabber:client") != null)
      localEMMessage.setAttribute("isencrypted", true);
    return processEMMessage(localEMMessage);
  }

  private void processGroupMessage(Message paramMessage, EMMessage paramEMMessage)
  {
    String str1 = paramMessage.getFrom();
    int i = str1.indexOf("/");
    String str3 = null;
    String str2;
    if (i > 0)
    {
      str3 = str1.substring(i + 1);
      str2 = str1.substring(0, i - 1);
    }
    else
    {
      EMLog.d("groupchatlistener", "the message is from muc itself");
      str2 = str1;
      str3 = "EaseMobGroup";
    }
    String str4 = EMContactManager.getGroupIdFromEid(str2);
    EMLog.d("groupchatlistener", "group msg groupjid:" + str2 + " groupid:" + str4 + " usrname:" + str3);
    paramEMMessage.setChatType(EMMessage.ChatType.GroupChat);
    paramEMMessage.setTo(str4);
  }
}

/* Location:           D:\hygieia\userclient\common\libs\easemobchat_2.1.8.jar
 * Qualified Name:     com.easemob.chat.GroupChatListener
 * JD-Core Version:    0.6.1
 */